<div class="container-fluid">
    <form class="form-horizontal" id="form" action="<?php echo URL::base(true)?>supplier/supplierSku/index" method="get">
        <div class="control-group">
            <label class="control-label">SKU:</label>
            <div class="controls">
                <input type="text" class="input-clear" name="sku" value="">
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="supplier_name">供应商:</label>
            <div class="controls" id="group2">
                <input type="text" class="input-clear" name="supplier_name" id="supplier_name" value="" />

            </div>
        </div>
        <div class="control-group">
            <div class="controls">
                <input type="submit"  class="btn btn-info" name="supplierbanksearch" value="查询">
                <button class="btn" type="reset" id="reset">重置</button>
            </div>
        </div>
        <div class="control-group pull-right">
            <input type="submit"  class="btn" name="searchdowm" value="查询导出">
            <input type="button"  class="btn" name="click-down" id="click-down" value="选择导出">
            <?php if(ACL::check('supplierSku_update')){?>
                <button class="btn" type="button" data-toggle="modal" data-target="#btn_import" style="margin-right: 10px;">批量导入处理</button>
            <?php }?>
            <?php if(ACL::check('supplierSku_del')){?>
                <button class="btn btn-danger" type="button" id="delete">批量删除</button>
            <?php }?>
        </div>
    </form>
    <form action="" method="POST" id="postform">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th><input type="checkbox" id="chooseall"/></th>
                    <th>供应商ID</th>
                    <th>供应商名称</th>
                    <th>SKU</th>
                    <th>名称</th>
                    <th>退税</th>
                    <th>退税率</th>
                    <th>加点税率</th>
                    <th>单价</th>
                    <th>规格</th>
                    <th>单位</th>
                    <th>交期</th>
                    <th>备注</th>
                    <th>添加时间</th>
                    <th width="70">操作</th>
                </tr>
            </thead>
            <?php
            if(isset($re_lists)) {
                foreach($re_lists as $num=>$data){
            ?>
            <tr id="select_<?php echo $data['id']; ?>">
                <td><input type="checkbox" name="id[]" value="<?php echo $data['id']; ?>"/></td>
                <td><?php echo isset($data['supplier_id'])?$data['supplier_id']:0; ?></td>
                <td><?php echo isset($data['supplier_name'])?$data['supplier_name']:0; ?></td>
                <td><?php echo isset($data['sku'])?$data['sku']:''; ?></td>
                <td><?php echo isset($data['productname'])?$data['productname']:'';?></td>
                <td><?php echo $data['export_tax_rebate']==1?'是':'否';?>
                <td><?php echo $data['rebate'];?></td>
                <td><?php echo $data['real_tax_rate'];?></td>
                <td><?php echo isset($data['price'])?$data['price']:'';?></td>
                <td><?php echo isset($data['size'])?$data['size']:'';?></td>
                <td><?php echo isset($data['nuit'])?$data['nuit']:''; ?></td>
                <td><?php echo isset($data['delivery'])?$data['delivery']:''; ?></td>
                <td><?php echo isset($data['remark'])?$data['remark']:''; ?></td>
                <td><?php echo isset($data['create_time'])?$data['create_time']:'0000-00-00 00:00:00'; ?></td>
                <td>
                    <div class="dropdown">
                        <button type="button" class="btn dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown">
                            操作 <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                            <?php if(ACL::check('supplierSku_update')){?>
                            <li role="presentation"><a href="javascript:update('<?php echo $data['id'];?>')">修改</a></li>
                            <?php }?>
                            <?php if(ACL::check('supplierSku_del')){?>
                            <li role="presentation"><a href="javascript:del('<?php echo $data['id'];?>')">删除</a></li>
                             <?php }?>
                        </ul>
                    </div>
                </td>
            </tr>
            <?php 
                }
            }
            ?>
        </table>
    </form>
</div>
<div><?php echo isset($pagination)?$pagination:NULL?></div>
<!--导入文件 -->
<div class="modal fade" id="btn_import">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                    <span class="sr-only">关闭</span>
                </button>
                <h4 class="modal-title">导入文件<span style="color: red">（导入请使用xls类型的）</span></h4>
            </div>
            <div class="alert alert-info text-center" role="alert">
                <p>模板下载: <a href="<?php echo URL::base();?>xlstemplate/supplierSku.xls">点击下载模板</a></p>
            </div>
            <form action="<?php echo URL::base();?>supplier/supplierSku/upload" method="post" enctype="multipart/form-data" id="upSku">
                <div class="modal-body form-horizontal" style="text-align: center">
                    <div class="form-group"><label class="col-md-3 control-label required">上传文件</label>
                        <div class="col-md-4">
                            <input type='file' style="line-height: 0px;" name='xls' class="inputxt" datatype="/.+\.xls/"  nullmsg="请选择上传文件"  errormsg="文件格式只能为xls"/>
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 20px">
                        <button id="submit-button" type="submit" class="col-md-offset-3 col-md-1 btn btn-success">确定导入</button>
                        <button type="button" class="btn" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/css/style.css" type="text/css" media="all" />
<script src="<?php echo URL::base() ?>media/js/jquery-1.10.1.min.js"></script>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css" media="all" />
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<script src="<?php echo URL::base() ?>media/layer/layer.js"></script>
<link rel="stylesheet"  href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css" media="all"/>

<script type="text/javascript">    
$(function(){
    $('input[name=sku]').val("<?php echo isset($_GET['sku'])?$_GET['sku']:'';?>");
    $('input[name=supplier_id]').val("<?php echo isset($_GET['supplier_id'])?$_GET['supplier_id']:'';?>");
    $('input[name=supplier_name]').val("<?php echo isset($_GET['supplier_name'])?$_GET['supplier_name']:'';?>");
    $('#reset').click(function(){
        $('.input-clear').val("");
    });
    $('#chooseall').click(function () {
        if (this.checked) {
            $("input[name='choose']").prop('checked', true);
        } else {
            $("input[name='choose']").prop('checked', false);
        }
    });
    $('button#delete').click(function () {
        layer.confirm('你确定要删除吗？', {btn: ['确定','取消']}, function(){
            $('form#postform').attr('action', '<?php echo URL::base(true)?>supplier/supplierSku/all_del');
            var checked = false;
            $('input[name="id[]"]').each(function () {
                this.checked && (checked = true);
            });
            if(!checked) {
                layer.alert('请选择要删除的数据',{icon:5});
            } else {
                $('form#postform').submit();
            }
        });
    });
    $('input#click-down').click(function () {
        $('form#postform').attr('action', '<?php echo URL::base(true)?>supplier/supplierSku/click_down');
        var checked = false;
        $('input[name="id[]"]').each(function () {
             this.checked && (checked = true);
        });
        if(!checked) {
            layer.alert('请选择要导出的数据',{icon:5});
        } else {
            $('form#postform').submit();
        }
    });
});
function del(id) {
    layer.confirm('你确定要删除吗？', {btn: ['确定','取消']}, function(){
        $.get('<?php echo URL::base(true)?>supplier/supplierSku/del?id='+id,function (data) {
            layer.alert(data, {icon: 6,closeBtn: 0},function () {
                window.location.reload();
            });
        });
    });
}
function update(id) {
    var url = "<?php echo url::base(true);?>supplier/supplierSku/update";
    $.get(url, {id: id,link:$('#form').serialize()}, function (data) {
        art.dialog({
            title:'供应商sku修改',
            lock: true,
            opacity: 0.87,	// 透明度
            content: data,
            width: '60%',
            height: '60%',
            button: [{
                name: '关闭',
                callback: function () {
                    window.location.reload();
                }
            }]
        });
    });
}
// 查询供应商自动提示补全
$("#supplier_name").autocomplete({
   autoFocus: true,
   minLength: 0,
   autoFill: true,
   source: '<?php echo URL::base(true)?>purchase/get_supplier',
   select: function (event, ui) {
       //从建议列表中选中之后触发的事件
       $("#supplier_name").val(ui.item.name);
       return false;
   }
});
</script>